﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Mindfor.Web.Models;

namespace Mindfor.Web
{
	/// <summary>
	/// Indicates that specified action is section of admin panel.
	/// </summary>
	[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
	public class AdminLinkAttribute : FilterAttribute, IActionFilter
	{
		/// <summary>
		/// Gets or sets title of the link to this admin module.
		/// </summary>
		public string Title { get; set; }

		/// <summary>
		/// Gets or sets admin link category.
		/// </summary>
		public string Category { get; set; }

		/// <summary>
		/// True, if causes admin toolbar to appear.
		/// </summary>
		public bool ShowManageToolbar { get; set; }

		/// <summary>
		/// Creates new management link attribute.
		/// </summary>
		public AdminLinkAttribute()
		{
			ShowManageToolbar = true;
		}

		/// <summary>
		/// Creates new admin link attribute with specified title.
		/// </summary>
		/// <param name="title">Title of the link to this admin module.</param>
		/// <param name="category">Category of the admin link.</param>
		public AdminLinkAttribute(string title, string category = "")
		{
			this.Title = title;
			this.Category = category;
			this.ShowManageToolbar = true;
		}

		public void OnActionExecuted(ActionExecutedContext filterContext)
		{
			//PageTitleCollection title = filterContext.Controller.ViewData.GetPageTitle();
			//if (title != null)
			//{
			//    UrlHelper url = new UrlHelper(filterContext.RequestContext);
			//    string dashboard = url.ActionModule("Dashboard", "System", "System");
			//    title.Insert(0, new PageTitleNode("Панель управления", true) { Url = dashboard });
			//}
		}

		public void OnActionExecuting(ActionExecutingContext filterContext)
		{
		}
	}
}
